package com.cloud.tsp.controller;

import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.alarm.Accident;
import com.cloud.api.domain.alarm.QueryAccident;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IAccidentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-22
 */
@RestController
@RequestMapping("/accident")
public class AccidentController {

    @Resource
    private IAccidentService accidentService;

    @Tag(name = "v1.0")
    @Operation(summary = "查询事故管理列表（管理）")
    @PostMapping("/getAccidentList")
    @Log(title = "事故管理-查询事故管理列表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<Accident> selectAccidentList(@RequestBody @Valid QueryAccident para){
        return accidentService.selectAccidentList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改事故（管理）")
    @PostMapping("/InsertOrUpdate")
    @Log(title = "事故管理-新增或修改事故", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdate(@RequestBody @Valid Accident para){
        accidentService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "查询事故详细（管理）")
    @PostMapping("/getById")
    @Log(title = "事故管理-查询事故详细", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<Accident> selectById(@RequestBody @Valid StrVo para){
        return R.ok(accidentService.getById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除事故（管理）")
    @PostMapping("/deleteById")
    @Log(title = "事故管理-删除事故", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deleteById(@RequestBody @Valid StrVo para){
        accidentService.removeById(para.getId());
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "事故数据导出")
    @PostMapping("/exportAccidentList")
    @Log(title = "事故管理-事故数据导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportAccidentList(QueryAccident para, HttpServletResponse response) throws IOException {
        accidentService.exportAccidentList(para,response);
    }
}